package httpDownload;

public class HttpHead {
	private String url;
	private String host;
	private int port = 80;
	private String  relativeUrl;  //相对路径
	private long len;
	private long begin = 0;
	private long offset = 0;
	
	public  HttpHead(String url){
		this.url = url;
	}
	public  HttpHead(String url,long begin,long offset){
		this.url = url;
		this.begin = begin;
		this.offset = offset;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}
	public String getRelativeUrl() {
		return relativeUrl;
	}
	public void setRelativeUrl(String relativeUrl) {
		this.relativeUrl = relativeUrl;
	}
	public long getLen() {
		return len;
	}
	public void setLen(long len) {
		this.len = len;
	}
	public long getBegin() {
		return begin;
	}
	public void setBegin(long begin) {
		this.begin = begin;
	}

	public long getOffset() {
		return offset;
	}
	public void setOffset(long offset) {
		this.offset = offset;
	}
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("GET ").append(relativeUrl).append(" HTTP/1.1").append("\r\n");
		sb.append("Host: ").append(host).append("\r\n");
		sb.append("Connection: Keep-Alive\r\n");
		if(offset != 0)
			sb.append("Range: bytes=").append(begin).append("-").append(begin+offset).append("\r\n");
		sb.append("\r\n");
		return sb.toString();
	}
	
	public HttpHead copy(long begin,long offset){
		HttpHead head =  new HttpHead(this.url, begin, offset);
		head.setHost(host);
		head.setRelativeUrl(relativeUrl);
		head.setLen(offset + 1);
		head.setPort(port);
		return head;
	}
	
}
